package LeetCode;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/17.
//
//https://leetcode.cn/problems/first-missing-positive/description/
public class 缺失的第一个正数 {
    public static void main(String[] args) {
        int[] nums = {2147483647};
        System.out.println(firstMissingPositive(nums));
    }
    public static int firstMissingPositive(int[] nums) {
        int max = 0;
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] > max)max = nums[i];
            set.add(nums[i]);
        }
        for (int i = 1; i < max; i++) {
            if(!set.contains(i)){
                return i;
            }
        }
        return max + 1;
    }
}
